package com.dingreading.cloud.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 空指针处理类
 */
public class StringUtil {

    /**
     * 判断是否全为汉字
     */
    public static boolean isChinese(String str) {
        String regEx = "[\\u4e00-\\u9fa5]+";
        return str.matches(regEx);
    }

    /**
     * 判断字符串包含数字
     */
    public static boolean containsNumber(String str) {
        boolean flag = false;
        Pattern pattern = Pattern.compile("[0-9]+");
        Matcher matcher = pattern.matcher(str);
        if (matcher.find()) {
            flag = true;
        }
        return flag;
    }

    /**
     * 判断是否为整数
     */
    public static boolean isInteger(String str) {
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();

    }

    /**
     * 判断是否微信号或qq号
     */
    public static boolean isQQOrWX(String str) {
        //QQ号最短5位，微信号最短是6位最长20位
        Pattern pattern = Pattern.compile("^[a-zA-Z0-9_-]{6,20}$");
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();

    }

//    public static void main(String[] args) {
//        System.out.println(isChinese("杜甫"));
//        System.out.println(isChinese("1杜甫"));
//        System.out.println(isChinese("杜2甫"));
//        System.out.println(isChinese("杜甫3"));
//        System.out.println(isChinese("杜甫*"));
//        System.out.println(isChinese("杜!甫"));
//    }

}
